package io.renren.modules.yst.service.impl;

import io.renren.modules.sys.entity.SysCaptchaEntity;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.yst.entity.WorkerEntity;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.yst.dao.WorkerCardDao;
import io.renren.modules.yst.entity.WorkerCardEntity;
import io.renren.modules.yst.service.WorkerCardService;


@Service("workerCardService")
public class WorkerCardServiceImpl extends ServiceImpl<WorkerCardDao, WorkerCardEntity> implements WorkerCardService {



    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WorkerCardEntity> page = this.page(
                new Query<WorkerCardEntity>().getPage(params),
                new QueryWrapper<WorkerCardEntity>()
        );

        return new PageUtils(page);
    }
    @Override
    public WorkerCardEntity queryById(Long workCardId) {
        return baseMapper.selectById(workCardId);
    }

    @Override
    public void create(WorkerEntity workerEntity, SysUserEntity sysUserEntity) {
        WorkerCardEntity workCardEntity=new WorkerCardEntity();
        workCardEntity.setCreateTime(new Date());
        workCardEntity.setWorkerId(workerEntity.getWorkerId());


        baseMapper.insert(workCardEntity);
    }

    @Override
    public WorkerCardEntity getlastOne(Long workerId) {
        return  this.getOne(new QueryWrapper<WorkerCardEntity>().eq("worker_id", workerId).orderByDesc("create_time").last("limit 1"));
    }

    @Override
    public List getWorkerCardIDs(Long workerId) {
        return baseMapper.selectObjs(new QueryWrapper<WorkerCardEntity>().eq("worker_id", workerId));
    }

}